import {Themes} from "./theme.slint";
import {ThemePadding,PaddingType,PaddingProps} from "./padding.slint";
import {FontProps, TextAlignmentProps, TextActionProps} from "./text.slint";
import { BorderType,BorderProps,ThemeBorder } from "./border.slint";
import { ShadowType,ShadowProps } from "./shadow.slint";
import {ThemeColor,ColorLevel,ColorProps} from "./color.slint";
import {ResultType} from "./result.slint";
import {ThemeSpace} from "./spacing.slint";
import {Size,SizeProps} from "./size.slint";
import {ROOT-STYLES} from "../../themes/src/theme.slint";


export global UseSurrealismFn {
  pure public function is-leap-year(year: int) -> bool {
      if Math.mod(year, 4) == 0 {
          if Math.mod(year, 100) == 0 {
              return Math.mod(year, 400) == 0;
          }
          return true;
      }
      return false;
  }
  // zeller algorithm to get days
  pure public function get-days(year: int, month: int, day: int) -> int {
    
    if month < 3 {
        return mod( day + floor((13 * ((month + 12) + 1)) / 5) + mod((year - 1) , 100) + floor(mod((year - 1) , 100) / 4) + floor((floor((year - 1) / 100)) / 4) - 2 * floor((year - 1) / 100) , 7);
    }
    return mod( day + floor((13 * (month + 1)) / 5) + mod(year , 100) + floor(mod(year , 100) / 4) + floor((floor(year / 100)) / 4) - 2 * floor(year / 100) , 7);
  }
  // get the day of the week
  pure public function get-weekday(year: int, month: int, day: int) -> int {
    return Math.mod((get-days(year, month, day) + 5), 7);
  }
  // 计算组件高度
  pure public function count-height(h:length,padding:length)->length {
    return h + padding * 2;
  }
  // 计算组件宽度
  pure public function count-width(w:length,padding:length)->length {
    return w + padding * 2;
  }
  pure public function get-padding(size:PaddingType)->PaddingProps {
    if(size==PaddingType.Small){
      ROOT-STYLES.sur-padding.small
    }else if(size==PaddingType.Normal){
      ROOT-STYLES.sur-padding.normal
    }else if(size==PaddingType.Large){
      ROOT-STYLES.sur-padding.large
    }else if(size==PaddingType.None){
      ROOT-STYLES.sur-padding.none
    }else if(size==PaddingType.Tip){
      ROOT-STYLES.sur-padding.tip
    }else if(size==PaddingType.Tag){
      ROOT-STYLES.sur-padding.tag
    }else{
      ROOT-STYLES.sur-padding.icon
    }
  }
  pure public function get-shadow(shadow:ShadowType)->ShadowProps {
    if(shadow==ShadowType.Low1){
      ROOT-STYLES.sur-shadow.low1
    }else if(shadow==ShadowType.Low2){
      ROOT-STYLES.sur-shadow.low2
    }else if(shadow==ShadowType.Low3){
      ROOT-STYLES.sur-shadow.low3
    }else if(shadow==ShadowType.High1){
      ROOT-STYLES.sur-shadow.high1
    }else if(shadow==ShadowType.High2){
      ROOT-STYLES.sur-shadow.high2
    }else {
      ROOT-STYLES.sur-shadow.high-empty
    }
  }
  pure public function get-shadow-x(shadow:ShadowType)->length {
    if(shadow==ShadowType.Low1){
      ROOT-STYLES.sur-shadow.low1.x
    }else if(shadow==ShadowType.Low2){
      ROOT-STYLES.sur-shadow.low2.x
    }else if(shadow==ShadowType.Low3){
      ROOT-STYLES.sur-shadow.low3.x
    }else if(shadow==ShadowType.High1){
      ROOT-STYLES.sur-shadow.high1.x
    }else if(shadow==ShadowType.High2){
      ROOT-STYLES.sur-shadow.high2.x
    }else {
      ROOT-STYLES.sur-shadow.high-empty.x
    }
  }
  pure public function get-shadow-y(shadow:ShadowType)->length {
    if(shadow==ShadowType.Low1){
      ROOT-STYLES.sur-shadow.low1.y
    }else if(shadow==ShadowType.Low2){
      ROOT-STYLES.sur-shadow.low2.y
    }else if(shadow==ShadowType.Low3){
      ROOT-STYLES.sur-shadow.low3.y
    }else if(shadow==ShadowType.High1){
      ROOT-STYLES.sur-shadow.high1.y
    }else if(shadow==ShadowType.High2){
      ROOT-STYLES.sur-shadow.high2.y
    }else {
      ROOT-STYLES.sur-shadow.high-empty.y
    }
  }
  pure public function get-shadow-blur(shadow:ShadowType)->length {
    if(shadow==ShadowType.Low1){
      ROOT-STYLES.sur-shadow.low1.blur
    }else if(shadow==ShadowType.Low2){
      ROOT-STYLES.sur-shadow.low2.blur
    }else if(shadow==ShadowType.Low3){
      ROOT-STYLES.sur-shadow.low3.blur
    }else if(shadow==ShadowType.High1){
      ROOT-STYLES.sur-shadow.high1.blur
    }else if(shadow==ShadowType.High2){
      ROOT-STYLES.sur-shadow.high2.blur
    }else {
      ROOT-STYLES.sur-shadow.high-empty.blur
    }
  }
  pure public function get-border(border:BorderType)->BorderProps {
    if(border==BorderType.Small){
      ROOT-STYLES.sur-border.small
    }else if(border==BorderType.Normal){
      ROOT-STYLES.sur-border.normal
    }else if(border==BorderType.Large){
      ROOT-STYLES.sur-border.large
    }else if(border==BorderType.X-Large){
      ROOT-STYLES.sur-border.x-large
    }else if(border==BorderType.Circle-None){
      ROOT-STYLES.sur-border.circle.none
    }else if(border==BorderType.Circle-Small){
      ROOT-STYLES.sur-border.circle.small
    }else if(border==BorderType.Circle-Normal){
      ROOT-STYLES.sur-border.circle.normal
    }else if(border==BorderType.Circle-Large){
      ROOT-STYLES.sur-border.circle.large
    }else if(border==BorderType.Circle-X-Large){
      ROOT-STYLES.sur-border.circle.x-large
    }else{
      ROOT-STYLES.sur-border.none
    }
  }
  pure public function get-space(w:length) -> length{
    if(w>=560px){
      ROOT-STYLES.sur-spacing.len560
    }else if(w>=520px){
      ROOT-STYLES.sur-spacing.len520
    }else if(w>=480px){
      ROOT-STYLES.sur-spacing.len480
    }else if(w>=440px){
      ROOT-STYLES.sur-spacing.len440
    }else if(w>=400px){
      ROOT-STYLES.sur-spacing.len400
    }else if(w>=360px){
      ROOT-STYLES.sur-spacing.len360
    }else if(w>=320px){
      ROOT-STYLES.sur-spacing.len320
    }else if(w>=280px){
      ROOT-STYLES.sur-spacing.len280
    }else if(w>=240px){
      ROOT-STYLES.sur-spacing.len240
    }else if(w>=200px){
      ROOT-STYLES.sur-spacing.len200
    }else if(w>=160px){
      ROOT-STYLES.sur-spacing.len160
    }else if(w>=120px){
      ROOT-STYLES.sur-spacing.len120
    }else if(w>=80px){
      ROOT-STYLES.sur-spacing.len80
    }else if(w>=60px){
      ROOT-STYLES.sur-spacing.len60
    }else if(w>=40px){
      ROOT-STYLES.sur-spacing.len40
    }else if(w>=20px){
      ROOT-STYLES.sur-spacing.len20
    }else{
      ROOT-STYLES.sur-spacing.none
    }
  }
  pure public function deeper(theme:Themes,color:brush)->brush {
    if(theme==Themes.Light){
      UseSurrealismFn.light-deeper(color)
    }else if(theme==Themes.Primary){
      UseSurrealismFn.primary-deeper(color)
    }else if(theme==Themes.Success){
      UseSurrealismFn.success-deeper(color)
    }else if(theme==Themes.Info){
      UseSurrealismFn.info-deeper(color)
    }else if(theme==Themes.Warning){
      UseSurrealismFn.warning-deeper(color)
    }else if(theme==Themes.Error){
      UseSurrealismFn.error-deeper(color)
    }else{
      UseSurrealismFn.dark-deeper(color)
    }
  }
  pure public function light-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.light.weakest){
      ROOT-STYLES.sur-theme-colors.light.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.light.weaker){
      ROOT-STYLES.sur-theme-colors.light.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.light.normal){
      ROOT-STYLES.sur-theme-colors.light.deeper
    }else{
      ROOT-STYLES.sur-theme-colors.light.deepest
    }
  }
  pure public function primary-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.primary.weakest){
      ROOT-STYLES.sur-theme-colors.primary.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.primary.weaker){
      ROOT-STYLES.sur-theme-colors.primary.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.primary.normal){
      ROOT-STYLES.sur-theme-colors.primary.deeper
    }else{
      ROOT-STYLES.sur-theme-colors.primary.deepest
    }
  }
  pure public function success-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.success.weakest){
      ROOT-STYLES.sur-theme-colors.success.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.success.weaker){
      ROOT-STYLES.sur-theme-colors.success.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.success.normal){
      ROOT-STYLES.sur-theme-colors.success.deeper
    }else{
      ROOT-STYLES.sur-theme-colors.success.deepest
    }
  }
  pure public function info-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.info.weakest){
      ROOT-STYLES.sur-theme-colors.info.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.info.weaker){
      ROOT-STYLES.sur-theme-colors.info.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.info.normal){
      ROOT-STYLES.sur-theme-colors.info.deeper
    }else{
      ROOT-STYLES.sur-theme-colors.info.deepest
    }
  }
  pure public function warning-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.warning.weakest){
    ROOT-STYLES.sur-theme-colors.warning.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.warning.weaker){
    ROOT-STYLES.sur-theme-colors.warning.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.warning.normal){
    ROOT-STYLES.sur-theme-colors.warning.deeper
    }else{
    ROOT-STYLES.sur-theme-colors.warning.deepest
    }
  }
  pure public function error-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.error.weakest){
    ROOT-STYLES.sur-theme-colors.error.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.error.weaker){
    ROOT-STYLES.sur-theme-colors.error.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.error.normal){
    ROOT-STYLES.sur-theme-colors.error.deeper
    }else{
    ROOT-STYLES.sur-theme-colors.error.deepest
    }
  }
  pure public function dark-deeper(color:brush)->brush {
    if(color==ROOT-STYLES.sur-theme-colors.dark.weakest){
    ROOT-STYLES.sur-theme-colors.dark.weaker
    }else if(color==ROOT-STYLES.sur-theme-colors.dark.weaker){
    ROOT-STYLES.sur-theme-colors.dark.normal
    }else if(color==ROOT-STYLES.sur-theme-colors.dark.normal){
    ROOT-STYLES.sur-theme-colors.dark.deeper
    }else{
    ROOT-STYLES.sur-theme-colors.dark.deepest
    }
  }
  pure public function get-color(theme:Themes,level:ColorLevel)->brush{
    if(theme==Themes.Light){
      return get-color-light(level);
    }else if(theme==Themes.Dark){
      return get-color-dark(level);
    }else if(theme==Themes.Error){
      return get-color-error(level);
    }else if(theme==Themes.Info){
      return get-color-info(level);
    }else if(theme==Themes.Success){
      return get-color-success(level);
    }else if(theme==Themes.Primary){
      return get-color-primary(level);
    }else{
      return get-color-warning(level);
    }
  }
  pure public function get-color-light(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
      ROOT-STYLES.sur-theme-colors.light.font
    }else if(level==ColorLevel.Weakest){
      ROOT-STYLES.sur-theme-colors.light.weakest
    }else if(level==ColorLevel.Weaker){
      ROOT-STYLES.sur-theme-colors.light.weaker
    }else if(level==ColorLevel.Normal){
      ROOT-STYLES.sur-theme-colors.light.normal
    }else if(level==ColorLevel.Deeper){
      ROOT-STYLES.sur-theme-colors.light.deeper
    }else if(level==ColorLevel.Deepest){
      ROOT-STYLES.sur-theme-colors.light.deepest
    }else{
      ROOT-STYLES.sur-theme-colors.light.opacity
    }
  }
  pure public function get-color-dark(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
      ROOT-STYLES.sur-theme-colors.dark.font
    }else if(level==ColorLevel.Weakest){
      ROOT-STYLES.sur-theme-colors.dark.weakest
    }else if(level==ColorLevel.Weaker){
      ROOT-STYLES.sur-theme-colors.dark.weaker
    }else if(level==ColorLevel.Normal){
      ROOT-STYLES.sur-theme-colors.dark.normal
    }else if(level==ColorLevel.Deeper){
      ROOT-STYLES.sur-theme-colors.dark.deeper
    }else if(level==ColorLevel.Deepest){
      ROOT-STYLES.sur-theme-colors.dark.deepest
    }else{
      ROOT-STYLES.sur-theme-colors.dark.opacity
    }
  }
  pure public function get-color-primary(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
    ROOT-STYLES.sur-theme-colors.primary.font
    }else if(level==ColorLevel.Weakest){
    ROOT-STYLES.sur-theme-colors.primary.weakest
    }else if(level==ColorLevel.Weaker){
    ROOT-STYLES.sur-theme-colors.primary.weaker
    }else if(level==ColorLevel.Normal){
    ROOT-STYLES.sur-theme-colors.primary.normal
    }else if(level==ColorLevel.Deeper){
    ROOT-STYLES.sur-theme-colors.primary.deeper
    }else if(level==ColorLevel.Deepest){
    ROOT-STYLES.sur-theme-colors.primary.deepest
    }else{
    ROOT-STYLES.sur-theme-colors.primary.opacity
    }
  }
  pure public function get-color-info(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
    ROOT-STYLES.sur-theme-colors.info.font
    }else if(level==ColorLevel.Weakest){
    ROOT-STYLES.sur-theme-colors.info.weakest
    }else if(level==ColorLevel.Weaker){
    ROOT-STYLES.sur-theme-colors.info.weaker
    }else if(level==ColorLevel.Normal){
    ROOT-STYLES.sur-theme-colors.info.normal
    }else if(level==ColorLevel.Deeper){
    ROOT-STYLES.sur-theme-colors.info.deeper
    }else if(level==ColorLevel.Deepest){
    ROOT-STYLES.sur-theme-colors.info.deepest
    }else{
    ROOT-STYLES.sur-theme-colors.info.opacity
    }
  }
  pure public function get-color-error(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
    ROOT-STYLES.sur-theme-colors.error.font
    }else if(level==ColorLevel.Weakest){
    ROOT-STYLES.sur-theme-colors.error.weakest
    }else if(level==ColorLevel.Weaker){
    ROOT-STYLES.sur-theme-colors.error.weaker
    }else if(level==ColorLevel.Normal){
    ROOT-STYLES.sur-theme-colors.error.normal
    }else if(level==ColorLevel.Deeper){
    ROOT-STYLES.sur-theme-colors.error.deeper
    }else if(level==ColorLevel.Deepest){
    ROOT-STYLES.sur-theme-colors.error.deepest
    }else{
    ROOT-STYLES.sur-theme-colors.error.opacity
    }
  }
  pure public function get-color-success(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
    ROOT-STYLES.sur-theme-colors.success.font
    }else if(level==ColorLevel.Weakest){
    ROOT-STYLES.sur-theme-colors.success.weakest
    }else if(level==ColorLevel.Weaker){
    ROOT-STYLES.sur-theme-colors.success.weaker
    }else if(level==ColorLevel.Normal){
    ROOT-STYLES.sur-theme-colors.success.normal
    }else if(level==ColorLevel.Deeper){
    ROOT-STYLES.sur-theme-colors.success.deeper
    }else if(level==ColorLevel.Deepest){
    ROOT-STYLES.sur-theme-colors.success.deepest
    }else{
    ROOT-STYLES.sur-theme-colors.success.opacity
    }
  }
  pure public function get-color-warning(level:ColorLevel)->brush {
    if(level==ColorLevel.Font){
    ROOT-STYLES.sur-theme-colors.warning.font
    }else if(level==ColorLevel.Weakest){
    ROOT-STYLES.sur-theme-colors.warning.weakest
    }else if(level==ColorLevel.Weaker){
    ROOT-STYLES.sur-theme-colors.warning.weaker
    }else if(level==ColorLevel.Normal){
    ROOT-STYLES.sur-theme-colors.warning.normal
    }else if(level==ColorLevel.Deeper){
    ROOT-STYLES.sur-theme-colors.warning.deeper
    }else if(level==ColorLevel.Deepest){
    ROOT-STYLES.sur-theme-colors.warning.deepest
    }else{
    ROOT-STYLES.sur-theme-colors.warning.opacity
    }
  }
  pure public function active-color() -> brush {
      return ROOT-STYLES.radio-active;
  }
}